﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DeviceInfoManage.BusinessLogicLayer;
public partial class SysMirrorList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /*对进行查询的设备类型下拉框各项进行设置*/
        if (!IsPostBack)
        {
            if (Session["adminUserName"] == null)
            {
                Response.Redirect("logout.aspx");
            }

            DataSet ds = (new reservedMan()).GetList();
            ddlErrType.DataSource = ds;
            ddlErrType.DataTextField = "reservedPathName";
            ddlErrType.DataValueField = "reservedPathName";
            ddlErrType.DataBind();
            ddlErrType.Items.Insert(0, new ListItem("=请选择=", ""));

            ds = (new Department()).GetDepartMentName();
            DeviceDpt.DataSource = ds;
            DeviceDpt.DataTextField = "departmentName";
            DeviceDpt.DataValueField = "departmentName";
            DeviceDpt.DataBind();
            DeviceDpt.Items.Insert(0, new ListItem("请选择", ""));

            Btn_Query_Click(null, null);
        }


    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标选择某行时变颜色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            //e.Row.Cells[6].Text = Convert.ToDateTime(e.Row.Cells[6].Text).ToShortDateString();
        }
    }

    protected void Btn_Query_Click(object sender, EventArgs e)
    {
        /*取得各个查询字段的内容然后调用业务类的QueryDevice函数进行查询*/
        reservedMan mr = new reservedMan();
        mr.departmentName = this.DeviceDpt.Text;
        mr.reservedPath = this.ddlErrType.Text;
        mr.deviceUser = this.txtdeviceUser.Text;
        mr.deviceSerialNumber = this.deviceNumber.Text;
        if (this.txtWHSJ.Text != "")
        {
            mr.reservedTime = DateTime.Parse(this.txtWHSJ.Text);
        }
        else
        {
            mr.reservedTime = DateTime.MinValue;
        }

        this.GridView1.DataSourceID = null;
        this.GridView1.DataSource = (new reservedMan()).QueryDevice(mr);
        this.GridView1.DataBind();

    }

    protected void btnDel_Click(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("cbox");
            if (cbox.Checked == true)
            {
                int docid = int.Parse(GridView1.DataKeys[i].Value.ToString());
                int outInfo = (new reservedMan()).Delete(docid);
                //Response.Write("<script>alert('" + outInfo + "');</script>");
            }
        }
        Response.Redirect("~/SysMirrorList.aspx");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Btn_Query_Click(null, null);
    }
}
